public class MethodReferenceDemo5 {
    public static void main(String[] args) {
        //1.使用lambda表达式
       // useStudentBuilder((name,age)->new Student(name,age));
        //2.使用引用构造器
        useStudentBuilder(Student::new);
        //注意：lambda表达式被构造器替代的时候，它的形式参数全部传递给构造器作为参数
    }
    private static void useStudentBuilder(StudentBuilder sb){
        Student stu = sb.build("Jack", 22);
        System.out.println(stu.getName() + " , " + stu.getAge());
    }
}

class Student{
    private String name;
    private int age;
    public Student(){}
    public Student(String name,int age){
        this.name = name;
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public String getName() {
        return name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }
}
interface StudentBuilder{
    Student build(String name,int age);
}
